﻿namespace GreenIsomer.Data.Entities.Transform {
	using System;
	using System.Xml.Serialization;
	using System.IO;
	
	[Serializable, XmlRoot("Settings", Namespace = Namespace)]
	[XmlInclude(typeof(EdmxInput))]
	[XmlInclude(typeof(SsdlOutput))]
	[XmlInclude(typeof(CsdlOutput))]
	[XmlInclude(typeof(MslOutput))]
	[XmlInclude(typeof(EdmxOutput))]
	public class Settings {

		public const string Namespace = "http://greenisomer.com/schema/data/entities/transform/settings/1.0/";

		public static Settings Load(string path) {
			XmlSerializer serializer = new XmlSerializer(typeof(Settings));
			using(TextReader reader = new StreamReader(path))
				return (Settings)serializer.Deserialize(reader);
		}

		[NonSerialized]
		private OutputCollection output;

		public Settings() {
			output = new OutputCollection();
		}

		[XmlElement("Input")]
		public Input Input { get; set; }

		[XmlElement("Output")]
		public OutputCollection Output {
			get { return output; }
		}

		public void Save(string path) {
			XmlSerializer serializer = new XmlSerializer(typeof(Settings));
			using(TextWriter writer = new StreamWriter(path))
				serializer.Serialize(writer, this);
			
		}

	}

}